Real-time communication between browsers (WebRTC) is a technology for performing real-time video and audio communication within browsers. The technology mainly uses the HyperText Markup Language (HTML) protocol and the JavaScript language and can implement communication between browsers without using a plug-in.
WebRTC is mainly used to implement point-to-point communication between browsers, so as to implement a real point-to-point connection between two browsers. In a process of establishing a session between browsers, media information of the browsers needs to be negotiated in the process of establishing the session, where the media information may include a media sending/receiving address, an encoding/decoding manner and a protocol used for media transmission, and the like, and is borne by using the Session Description Protocol (SDP). In the process of establishing the session, an OFFER/ANSWER mechanism of SDP is used to perform media information negotiation, such as audio and video negotiation, and negotiation on encoding/decoding manner used by the media. When a network has a network address translator (NAT) or a firewall device, further, the Interactive Connectivity Establishment (ICE,) needs to be used to negotiate an available ICE address to perform point-to-point transmission of session content, so as to establish a connection (PeerConnection) of a session generated by using the browsers, thereby enabling the browsers to communicate with each other.
In an existing process of establishing the session, when a calling browser needs to send a request for establishing a session, the calling browser further needs to collect an available ICE candidate address for traversing an NAT or a firewall so as to send and receive session content. A process of collecting an ICE candidate address mainly is sending, by a browser, a request to a Session Traversal Utilities for Network Address Translator (STUN) server or a Traversal Using Relay NAT (TURN) server that serves the browser. The STUN or TURN server returns to the browser, in a returned response, an external communication address (that is, an ICE address) or a relay address (that is, an ICE address) on the server after traversing the NAT or the firewall. After completing collection of the ICE candidate address, the browser may send the ICE candidate address to a called party (which may be an Internet Protocol (IP) Multimedia Subsystem (IMS) terminal, a browser, or a common terminal) in a request for establishing a session or in a separate message. If the called party also supports ICE negotiation, the called party further needs to, after receiving the ICE candidate address sent by the calling browser, collect an ICE candidate address of a called end and send a collected ICE candidate address to the calling browser. In other words, a calling party and the called party both need to perform ICE address negotiation, so as to find one most suitable ICE address pair for transmission of session content. A process of negotiating the ICE address pair thereof mainly is performing negotiation by each ICE candidate address of the called party with each ICE candidate address of the calling party (which specifically is sending an NAT request packet from each ICE candidate address of the called party to each ICE candidate address of the calling party, and waiting to receive a response returned by using the ICE candidate address of the calling party), and performing negotiation by each ICE candidate address of the calling party with each ICE candidate address of the called party (which specifically is sending a NAT request packet from each ICE candidate address of the calling party to each ICE candidate address of the called party, and waiting to receive a response returned by using the ICE candidate address of the called party). If multiple pairs of addresses can mutually send and receive a correct response, a determining mechanism (for example, according to a priority condition of an ICE candidate address, preference of an application, and the like) defined in the ICE protocol is used to select one optimal ICE address pair including a calling ICE address and a called ICE address as addresses of the calling browser and the called browser for performing transmission of session content.
In an existing session process by using the browsers, if the calling browser or the called browser is refreshed (that is, refreshing is caused by user clicking or the browser is temporarily restarted due to a network problem), in order to restore a connection of an original session, the browsers need to perform ICE re-negotiation. However, four handshake negotiations in this process is time-consuming, so that the transmission of the session content is obviously interrupted, which results in poor user experience.